/*
 *  Copyright 2008-2010 www.jrails.org
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.rails.extjs.panel;

import org.rails.extjs.BoxComponent;
import org.rails.extjs.Option;
import org.rails.extjs.Template;
import org.rails.extjs.data.Store;
import org.rails.extjs.javascript.JavaScript;

public class DataView extends BoxComponent {

	public DataView() {
		super();
	}

	public DataView(Option configOptions) {
		super(configOptions);
	}

	public DataView(String id) {
		super(id);
	}
	
	public void setBlockRefresh(Boolean blockRefresh){
		addOption("blockRefresh", blockRefresh);
	}
	
	public Boolean isBlockRefresh(){
		return getBoolean("blockRefresh", false);
	}
	
	public void setDeferEmptyText(Boolean deferEmptyText){
		addOption("deferEmptyText", deferEmptyText);
	}
	
	public Boolean isDeferEmptyText(){
		return getBoolean("deferEmptyText",false);
	}
	
	public void setEmptyText(String emptyText){
		addOption("emptyText", emptyText);
	}
	
	public String getEmptyText(){
		return getString("emptyText","");
	}
	
	public void setItemSelector(String itemSelector){
		addOption("itemSelector", itemSelector);
	}
	
	public String getItemSelector(){
		return getString("itemSelector","");
	}
	
	public void setLoadingText(String loadingText){
		addOption("loadingText", loadingText);
	}

	public String getLoadingText(){
		return getString("loadingText", "");
	}
	
	public void setMultiSelect(Boolean multiSelect){
		addOption("multiSelect", multiSelect);
	}
	
	public Boolean isMultiSelect(){
		return getBoolean("multiSelect", false);
	}
	
	public void setOverClass(String overClass){
		addOption("overClass", overClass);
	}
	
	public String getOverClass(){
		return getString("overClass", "");
	}
	
	public void setSelectedClass(String selectedClass){
		addOption("selectedClass", selectedClass);
	}
	
	public String getSelectedClass(){
		return getString("selectedClass", "x-view-selected");
	}
	
	public void setSimpleSelect(Boolean simpleSelect){
		addOption("simpleSelect", simpleSelect);
	}
	
	public Boolean isSimpleSelect(){
		return getBoolean("simpleSelect", false);
	}
	
	public void setSingleSelect(Boolean singleSelect){
		addOption("singleSelect", singleSelect);
	}
	
	public Boolean isSingleSelect(){
		return getBoolean("singleSelect",false);
	}
	
	public void setStore(Store store){
		addOption("store",store);
	}
	
	public Store getStore(){
		if(getOption("store") instanceof Store)
			return (Store) getOption("store");
		else
			return null;
	}
	
	public void setStore(String storeId){
		addOption("store",new JavaScript("Ext.StoreMgr.lookup('{0}')",storeId));
	}
	
	public void setTpl(Template tpl){
		addOption("tpl", tpl);
	}
	
	public Template getTpl(){
		return (Template)getOption("tpl");
	}
	
	public void setTrackOver(Boolean trackOver){
		addOption("trackOver", trackOver);
	}
	
	public Boolean isTrackOver(){
		return getBoolean("trackOver", false);
	}
	
	
	@Override
	public String getScript() {
		script = new StringBuffer("");
		createItems();
		script.append("new Ext.DataView(");
		script.append(createOptions());
		script.append(")");
		return script.toString();
	}

}
